package cc.iotkit.generator.service;

import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.generator.core.PageBuilder;
import cc.iotkit.generator.dto.bo.DevicesByGroupIdBo;
import cc.iotkit.generator.dto.bo.RuleByPksBo;
import cc.iotkit.generator.mapper.RuleInfoDataMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RuleInfoService {
    @Autowired
    private RuleInfoDataMapper ruleInfoDataMapper;

    public Paging<RuleByPksBo> rulesByGroupId(String groupId, PageRequest<RuleByPksBo> request) {
        List<DevicesByGroupIdBo> list = ruleInfoDataMapper.selectDevicesByGroupId(groupId);
        Page<RuleByPksBo> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<RuleByPksBo> result =  ruleInfoDataMapper.selectRuleByPks(page, list, request.getData().getName());

        return new Paging<>(result.getTotal(), result.getRecords());
    }
}
